package org.xserver.bootstrap.listener;

import org.xserver.bootstrap.listener.exception.BootstrapListenerError;

/**
 * This is abstract class for bootstrap listener. The implement classes do the
 * real process works.
 * 
 * <pre>
 *  XServer support some bootstrap listener, as follow:
 *  <ul>
 *  <li>{@link MenuBootstrapListener}, it initialize the permission data maps</li>
 *  <li>{@link InterfaceMonitorBootstrapListener}, it initialize interface info by interfaceContest</li>
 *  <li>...</li>
 *  </ul>
 *  other process need provided, can implements AbstractBootstrapListener
 * </pre>
 * 
 * @author wangj
 * @since 2016/08/08
 *
 */
public abstract class AbstractBootstrapListener implements BootstrapListener {
	/**
	 * When the exceptionContinue is true that invoke
	 * {@link #process(String...)} will ignore exception and go next
	 * bootstrapListener. If the value is false, the process will interrupt when
	 * call {@link #process(String...)} throw exception
	 */
	private boolean exceptionContinue;

	@Override
	public boolean isExceptionContinue() {
		return exceptionContinue;
	}

	public void setExceptionContinue(boolean exceptionContinue) {
		this.exceptionContinue = exceptionContinue;
	}

	@Override
	public void process(String... args) throws BootstrapListenerError {
		beforeProcess();
		doProcess(args);
	}

	/**
	 * Before {@link #doProcess(String...)} maybe do some preparation, for example
	 * backup data. If nothing to do, subclass needn't to extend this method
	 * 
	 * @throws BootstrapListenerError
	 */
	protected void beforeProcess() throws BootstrapListenerError {
	}

	protected abstract void doProcess(String... args)
			throws BootstrapListenerError;

	@Override
	public String getName() {
		return this.getClass().getSimpleName();
	}

}
